package com.beforejava5;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description TODO
 * @Author zhouhai
 * @Date2018/9/710:19
 **/
public class ExecutorDemo {

    public static void main(String[] args) {

        //执行器，线程池是它的一种实现
        Executor executor = Executors.newFixedThreadPool(1);

        executor.execute(new Runnable() {
            @Override
            public void run() {
                System.out.printf("[Thread: %s]Hello,World ... \n", Thread.currentThread().getName());
            }
        });

        //合理的关闭线程池是非常重要的
        if (executor instanceof ExecutorService) {
            ExecutorService executorService = ExecutorService.class.cast(executor);

            executorService.shutdown();
        }

    }


}
